package com.ydc.ln.tutorial.algorithm;

/**
 * 
 * @author ydc
 * 
 */
public class GridTest {
	public static final int WALL = -9;
	public static final int PASS = -1;

	public void testGrid() {
		// 定义围墙
		int[][] grid = new int[7][9];
		// 初始化围墙
		for (int i = 0; i < grid.length; i++) {
			for (int j = 0; j < grid[i].length; j++) {
				grid[i][j] = (i == 0 || i == grid.length - 1 || j == 0 || j == grid[i].length - 1) ? WALL : PASS;
			}
		}
		// 设置已封锁的方格
		grid[1][3] = WALL;
		grid[2][3] = WALL;
		grid[2][4] = WALL;
		grid[3][5] = WALL;
		grid[4][4] = WALL;
		grid[4][5] = WALL;
		grid[4][6] = WALL;
		grid[5][1] = WALL;
		grid[5][5] = WALL;
		grid[6][1] = WALL;
		grid[6][2] = WALL;
		grid[6][3] = WALL;

		Offset[] offset = new Offset[4];
		offset[0] = new Offset(1, 0); // 向下移动
		offset[1] = new Offset(0, 1); // 向右移动
		offset[2] = new Offset(-1, 0); // 向上移动
		offset[3] = new Offset(0, -1); // 向左移动

		// 定义起始位置与目标位置
		Position startPos = new Position(2, 1);
		Position endPos = new Position(3, 6);

		boolean foundFlag = false;
		Position curPos = new Position(2, 1);

		Position tempPos = new Position(0, 0);

	}

}

/**
 * 偏移量
 * 
 * @author ydc
 * 
 */
class Offset {
	private int row;
	private int col;

	public Offset(int row, int col) {
		this.row = row;
		this.col = col;
	}

	public int getRow() {
		return row;
	}

	public void setRow(int row) {
		this.row = row;
	}

	public int getCol() {
		return col;
	}

	public void setCol(int col) {
		this.col = col;
	}
}

/**
 * 位置
 * 
 * @author ydc
 * 
 */
class Position {
	private int x;
	private int y;

	public Position(int x, int y) {
		this.x = x;
		this.y = y;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}
}
